package Test;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * 〈T1〉
 *
 * @author zhangsixian
 * @create 2021/6/16
 * @since 1.0.0
 */
public class T1 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        ArrayList<Integer> list = new ArrayList(n);
        for (int i = 0; i < n; i++) {
            int aa = s.nextInt();
            list.add(aa);
        }
        int x = s.nextInt();
        Integer min = null;
        Integer max = null;
        int num = 0;
        for (int j = 0; j < list.size(); j++) {
            for (int i = 0; i < list.size() - 1; i++) {
                min = list.get(i);
                max = list.get(i + 1);
                if (min > max) {
                    list.set(i, max);
                    list.set(i + 1, min);
                }
            }
        }
        ArrayList<Integer> maxList = new ArrayList();
        ArrayList<Integer> minList = new ArrayList();
        for (int i = 0; i < x; i++) {
            num = num + list.get(list.size() - i - 1);
            maxList.add(list.get(list.size() - i - 1));
            num += list.get(i);
            minList.add(list.get(i));
        }
        for (int i = 0; i < maxList.size() -1; i++) {
            if (maxList.get(i).equals(maxList.get(i + 1))){
                System.out.println(-1);
                return;
            }
            for (int j = 0; j < minList.size() - 1; j++) {
                if (maxList.get(i).equals(minList.get(j)) || minList.get(j).equals(minList.get(j + 1))) {
                    System.out.println(-1);
                    return;
                }
            }
        }
        TreeSet<Integer> aa = new TreeSet<>();

        System.out.println(num);
    }
}
